import request from '@/utils/request'
const API_PREFIX = '/api/v1/menu'

import { Menu } from './types.ts'
import { Option } from '../../types.ts'

/**
 *  获取菜单列表
 * @param params
 * @returns
 */
export const getMenuList = (params: Menu.Query) => {
    return request.get<Array<Menu.Row>>(`${API_PREFIX}/list`, { params })
}

/**
 * 获取菜单下拉列表
 */
export const getMenuOptions = () => {
    return request.get<Array<Option>>(`${API_PREFIX}/options`)
}

/**
 * 路由列表
 */
export const getRouteList = () => {
    return request.get<Array<Menu.Route>>(`${API_PREFIX}/routes`)
}
/**
 * 菜单详情
 * @param menuId
 * @returns
 */
export const getMenuDetail = (menuId: number) => {
    return request.get<Menu.Form>(`${API_PREFIX}/${menuId}/form`)
}

/**
 * 新增菜单
 * @param params
 * @returns
 */
export const saveMenu = (params: Menu.Form) => {
    return request.post(`${API_PREFIX}`, params)
}

/**
 * 修改菜单
 * @param params
 * @returns
 */
export const updateMenu = (params: Menu.Form) => {
    return request.put(`${API_PREFIX}/${params.id}`, params)
}

/**
 *
 */
export const deleteMenu = (id: number) => {
    return request.delete(`${API_PREFIX}/${id}`)
}

/**
 *  修改菜单显示状态
 * @param params
 * @returns
 */
export const updateMenuVisible = (params: any) => {
    return request.patch(`${API_PREFIX}/${params.id}`, { params })
}
